package com.itheima.controller;

import com.itheima.domain.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;
import java.util.List;

/**
 * @Author 王加鑫
 * @Date 2021/7/25 20:26
 * @Since JDK 1.9
 */
@Controller
public class ParmRequestController {

    /**
     * 对于controller 方法形参，int — Integer 这种包装数据类型
     * 应该使用基本数据类型的引用数据类型，基本数据类型不能为Null
     * @param name
     * @param age
     * @return
     */
    @RequestMapping("/parm01")
    public String parm01(String name,Integer age){
        System.out.println(name + "," + age);
        return "parm.jsp";
    }

    @RequestMapping("/parm02")
    public String parm02(User user){
        System.out.println(user);
        return "parm.jsp";
    }

    /**
     * @RequestParam用来区分参数
     * @param user
     * @param age123
     * @return
     */
    @RequestMapping("/parm03")
    public String parm03(User user,@RequestParam Integer age123){
        System.out.println(user + "," + age123);
        return "parm.jsp";
    }

    /**
     * 当pojo有复杂变量时
     * http://localhost/requestParam5?address.province=beijing
     * @param user
     * @return
     */
    @RequestMapping("/parm04")
    public String parm04(User user){
        System.out.println("user.address:" + user.getAddress());
        return "parm.jsp";
    }

    /**
     * http://localhost/parm05?addressList[0].province=安徽&addressList[0].city=安庆&
     * addressList[1].province=湖北&addressList[1].city=武汉
     * @param user
     * @return
     */
    @RequestMapping("/parm05")
    public String parm05(User user){
        System.out.println("user.addressList:" + user.getAddressList());
        return "parm.jsp";
    }

    /**
     * http://localhost/requestParam8?addressMap[’home’].province=bj&addressMap[’job’].province=tj
     * @param user
     * @return
     */
    @RequestMapping("/parm06")
    public String parm06(User user){
        System.out.println("user.addressMap:" + user.getAddressMap());
        return "parm.jsp";
    }

    /**
     * 数组类型传参
     * http://localhost/requestParam9?nick=Jockme&nick=zahc
     * @param
     * @return
     */
    @RequestMapping("/parm07")
    public String parm07(String[] str){
        for (int i = 0; i < str.length; i++) {
            System.out.println(str[i]);
        }
        return "parm.jsp";
    }

    /**
     * 集合类型传参
     * http://localhost/requestParam10?nick=Jockme&nick=zahc
     * @param str
     * @return
     */
    @RequestMapping("/parm08")
    public String parm08(@RequestParam("str") List<String> str){
        for (int i = 0; i < str.size(); i++) {
            System.out.println(str.get(i));
        }
        return "parm.jsp";
    }

    /**
     * 日期类型转换
     * @param date
     * @return
     */
    @RequestMapping("/parm09")
    public String parm09(Date date){
        System.out.println(date);
        return "parm.jsp";
    }

    @RequestMapping("/parm10")
    public String parm10(@DateTimeFormat(pattern = "yyyy年MM月dd号") Date date){
        System.out.println(date);
        return "parm.jsp";
    }


}
